package com.wanxi.servlet.navigation;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.VO.DeviceClassVO;
import com.wanxi.VO.NavigationVO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.DeviceClassService;
import com.wanxi.service.NavigationService;
import com.wanxi.service.impl.DeviceClassServiceImpl;
import com.wanxi.service.impl.NavigationServiceImpl;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : 林子淳
 * @create 2023/2/28 8:50
 */
//@WebServlet("/back/navigation/add")
public class NavigationAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2、获取前端传过来的值
        String name = req.getParameter("name");
        String link = req.getParameter("link");
        String enable = req.getParameter("enable");

        //3.封装VO数据
        NavigationVO navigationVO = new NavigationVO();
        navigationVO.setName(Tool.nullToStr(name));
        navigationVO.setEnable(Tool.strToInt(enable));
        navigationVO.setLink(Tool.nullToStr(link));

        // 4.调用服务逻辑层
        NavigationService navigation = new NavigationServiceImpl();
        //        5.得到返回的结果
        ResultDTO resultDTO = navigation.add(navigationVO);
        //        6.返回给前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }


}
